var qcloud = require('../../vendor/qcloud-weapp-client-sdk/index');
var config = require('../../config');
var util = require('../../utils/util.js')
//获取应用实例
var app = getApp()
Page({
  data: {
    getBoard: config.service.getBoard,
    inputValue: '0',
    name:'',
    room_id:'',
    listData:[],
    room_name: ''
  },
  onLoad: function (options) {
    var self = this;
    self.setData({
      room_id: options.room_id,
      room_name: options.room_name
    });
    wx.setNavigationBarTitle({
      title: self.data.room_name+' 的排行榜'
    });
    qcloud.request({
      url: self.data.getBoard,
      data: {
         room_id: self.data.room_id
      },
      login: true,
      success(resp) {
          if(resp.data.code === 0){
              var arr = [];
              var obj = resp.data.data.scoreboard;
              for(var key in obj){
                obj[key].user_info = JSON.parse(obj[key].user_info);
                arr.push(obj[key]);
              };
              self.setData({
                listData: arr
              });
          }else{
              util.showModel('fail', resp.data.message);
          }
      },
      fail(error) {
          console.log('request fail', error);
      },
      complete() {
          console.log('request complete');
      }
    });
    //调用应用实例的方法获取全局数据
    app.getUserInfo(function(userInfo){
      self.setData({
        items: self.data.items,
        userInfo: userInfo
      })
    })
  },
  onShareAppMessage: function () {
    return {
      title: '牌局风云榜在此,快来看看你排第几',
      path: 'pages/total/total?room_id=' + this.data.room_id +'&room_name='+ this.data.room_name,
      success: function(res) {
        wx.showToast({
            title: '分享成功',
            icon: 'success'
        });
      },
      fail: function(res) {
        wx.showToast({
            title: '分享失败',
            icon: 'success'
        });
      }
    }
  }
})
